﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;

namespace COFE.Data
{
    public class COFEDBConfiguration : ConfigurationSection
    {
        private static string cofedbConfig = "cofedb";
        private static COFEDBConfiguration _config = getConfig();

        /// <summary>
        /// Returns an COFEDBConfiguration instance
        /// </summary>
        public static COFEDBConfiguration Config { get { return _config; } }        
        
        private static COFEDBConfiguration getConfig()
        {

            return (COFEDBConfiguration)System.Configuration.ConfigurationManager.
               GetSection(COFEDBConfiguration.cofedbConfig) ??
               new COFEDBConfiguration();

        }

        [ConfigurationProperty("ConnectionString", IsRequired=false, 
            DefaultValue="")]
        public string ConnectionString
        {
            get { return (string)base["ConnectionString"]; }
            set { base["ConnectionString"] = value; }
        }

        [ConfigurationProperty("RandomEntryKeys", IsRequired = false,
           DefaultValue = true)]
        public bool RandomEntryKeys
        {
            get { return (bool)base["RandomEntryKeys"]; }
            set { base["RandomEntryKeys"] = value; }
        }

        [ConfigurationProperty("RecrusiveEntryDeletion", IsRequired = false,
          DefaultValue = true)]
        public bool RecrusiveEntryDeletion
        {
            get { return (bool)base["RecrusiveEntryDeletion"]; }
            set { base["RecrusiveEntryDeletion"] = value; }
        }

        /// <summary>
        /// Sqlite do not have Apply supported, 
        /// so some FilterExpression will query the output instead. 
        /// (e.g. getOutputExpression() instead of getExpression())
        /// </summary>
        [ConfigurationProperty("ApplySupported", IsRequired = false,
           DefaultValue = false)]
        public bool ApplySupported
        {
            get { return (bool)base["ApplySupported"]; }
            set { base["ApplySupported"] = value; }
        }

        /// <summary>
        /// COFEDBShared runs the following command to explicitly enable foreign primVolId 
        /// when new connection is created.
        /// PRAGMA foreign_keys = true;
        /// </summary>
        [ConfigurationProperty("Sqlite_EnableForeignKey", IsRequired = false, 
            DefaultValue=true)]        
        public bool Sqlite_EnableForeignKey
        {
            get { return (bool)base["Sqlite_EnableForeignKey"]; }
            set { base["Sqlite_EnableForeignKey"] = value; }
        }

    }
}
